#!/bin/bash

ip=$1
if [[ "x$ip" == "x" ]];then
	echo "param 1: ip is required."
	exit -1
fi
port=$2
if [[ "x$port" == "x" ]];then
	echo "param 2: port is required."
	exit -1
fi

for i in {2..254};do
#    echo $i
    {
        echo -e "\n" | telnet $1.$i $2 2> /dev/null | grep Connected
    }&
    times=$(echo "$i%20" | bc)
    if [[ $times == 0 ]]; then
        sleep 1
        kill `ps aux| grep telnet | grep -v grep | awk '{print $2}'`
    fi
done
sleep 1
kill `ps aux| grep telnet | grep -v grep | awk '{print $2}'`

